package com.example.shiwuyouproject.ui.fragment.home.activity

import android.content.Context
import android.graphics.Color
import android.view.View
import androidx.core.view.setPadding
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.PagerAdapter
import com.example.shiwuyouproject.base.BaseVmActivity
import com.example.shiwuyouproject.databinding.ActivityLatestrecruitmentBinding
import com.example.shiwuyouproject.ui.fragment.home.adapter.ViewPagerAdapter
import com.example.shiwuyouproject.ui.fragment.home.view.ScaleTransitionPagerTitleView
import com.example.shiwuyouproject.ui.fragment.home.viewmodel.LatestRecruitmentViewModel
import com.example.shiwuyouproject.utils.ActStartUtils
import com.example.shiwuyouproject.utils.DisplayUtil
import net.lucode.hackware.magicindicator.ViewPagerHelper
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView

/**
 * 最新招聘
 */
class LatestRecruitmentActivity :
    BaseVmActivity<ActivityLatestrecruitmentBinding, LatestRecruitmentViewModel>() {
    override fun viewModelClass(): Class<LatestRecruitmentViewModel> =
        LatestRecruitmentViewModel::class.java

    override fun getViewBinding(): ActivityLatestrecruitmentBinding {
        return ActivityLatestrecruitmentBinding.inflate(layoutInflater)
    }

    private val CHANNELS = arrayOf("推荐", "最新")
    override fun initView() {
        mBinding.myViewPager.adapter = ViewPagerAdapter(CHANNELS, supportFragmentManager)
    }

    override fun initData() {
        initMagicIndicator()

    }

    override fun setListener() {
        mBinding.tvBack.setOnClickListener { finish() }
        mBinding.clSercher.setOnClickListener { //搜索
            ActStartUtils.startAct(this, SearchForCoursesActivity::class.java)
        }
    }

    override fun observe() {


    }

    private fun initMagicIndicator() {
        val commonNavigator = CommonNavigator(this)
        commonNavigator.adapter = object : CommonNavigatorAdapter() {
            override fun getCount(): Int {
                return CHANNELS.size
            }

            override fun getTitleView(context: Context, index: Int): IPagerTitleView {
                val simplePagerTitleView: SimplePagerTitleView =
                    ScaleTransitionPagerTitleView(context)
                simplePagerTitleView.setPadding(
                    0,
                    0,
                    DisplayUtil.dip2px(this@LatestRecruitmentActivity, 50f),
                    0
                )
                simplePagerTitleView.text = CHANNELS[index]
                simplePagerTitleView.textSize = 17f
                simplePagerTitleView.normalColor = Color.parseColor("#8CFFFFFF")
                simplePagerTitleView.selectedColor = Color.parseColor("#FFFFFF")
                simplePagerTitleView.setOnClickListener { mBinding.myViewPager.currentItem = index }
                return simplePagerTitleView
            }

            override fun getIndicator(context: Context): IPagerIndicator? {
                return null
            }
        }
        mBinding.magicIndicator.navigator = commonNavigator
        ViewPagerHelper.bind(mBinding.magicIndicator, mBinding.myViewPager)
    }


}